<?php
$userObj = new user();
//---------------------------------------插入数据方法一----------------------------------------- 
//模拟ActiveRecord模式 插入数据
$userObj->username = 'hoho';
$userObj->passwd = '1478522';
$userObj->email = 'qsf.zzia@163.com';
$userObj->sex  = 1;    
$userObj->desc  = '清洁工';
$insetId = $userObj->insert(); 
if ($insetId > 0) {
    echo "插入ID为:{$insetId}<BR>";
}

//---------------------------------------插入数据方法二-----------------------------------------
//直接数组做参数插入数据
$userArr  = array(
    'username' => 'hoho',
    'passwd' => '1478522',
    'email' => 'qsf.zzia@163.com',
    'sex' => '1',    
    'desc' => '厨师',
);
$insetId = $userObj->insert($userArr);
if ($insetId > 0) {
    echo "插入ID为:{$insetId}<BR>";
}

//---------------------------------------更新数据方法一---------------------------------------- 
$userObj->username = 'h111oho';
$userObj->passwd = '1478511122';
$userObj->email = 'qsf.zz1112345678911111111ia@163.com';
$userObj->sex  = 1;    
$userObj->desc  = '清洁工';
$affectedRows1 = $userObj->update(89);
if ($affectedRows1 > 0) {
    echo "影响行数为:{$affectedRows1}<BR>";
}

//---------------------------------------更新数据方法二---------------------------------------- 
//更新记录（传递参数的方式和insert操作一样）
$userArr  = array(
    'username' => 'hohoho',
    'passwd' => '1474rr4448522',
    'email' => 'qsf.rrzzia@165.com',
    'sex' => '0',    
    'desc' => '厨师qq',
);
$affectedRows = $userObj->update($userArr, $insetId);
if ($affectedRows > 0) {
    echo "影响行数为:{$affectedRows}<BR>";
}

//----------------------------------------查询数据----------------------------------------------   
$userRs0 = $userObj->select(8);  //单个主键值
//print_r($userRs0);

$userRs1 = $userObj->select(array(1,5,8));   //多个主键值的数组  
//print_r($userRs1);

$userRs2 = $userObj->select('select count(*) as count from  user where uid > 20');  //直接完整sql语句
//print_r($userRs2);

$userRs3 = $userObj->select("`uid` > 0");  //where条件 
//print_r($userRs3); 

$userRs4 = $userObj->getOne("`uid` > 0"); //获取单条记录
//print_r($userRs4);

$usersRs5 = $userObj->getAll("`uid` > 0"); ////获取所有记录   
//print_r($usersRs5); 

$usersRs6 = $userObj->limit('0,10')->where('uid > 100')->order('uid DESC')->group('username')->select(); 
//print_r($usersRs6); 

//----------------------------------------删除数据----------------------------------------------- 
//删除操作传递参数的方式和select操作一样
$userObj->delete(60);  //单个主键值
$userObj->delete(array(1,5,8));   //多个主键值的数组  
$userObj->delete('delete  from  user where uid > 100');  //直接完整sql语句
$userObj->delete("`uid` > 100");  //where条件 
$userObj->limit('5')->where('uid > 80')->delete(); 
//----------------------------------------特殊查询----------------------------------------------- 
$userShowRs = $userObj->show('show create table user', true);  //获取特殊查询的结果,第二个参数代表返回一条结果还是所有的结果